home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 14BJHMN (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  4.9 KB  |  185 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.swing.event.ChangeEvent;
  4. import com.sun.java.swing.event.ChangeListener;
  5. import com.sun.java.swing.event.EventListenerList;
  6. import java.io.Serializable;
  7.  
  8. public class DefaultBoundedRangeModel implements BoundedRangeModel, Serializable {
  9.    protected transient ChangeEvent changeEvent = null;
  10.    protected EventListenerList listenerList = new EventListenerList();
  11.    private int value = 0;
  12.    private int extent = 0;
  13.    private int min = 0;
  14.    private int max = 100;
  15.    private boolean isAdjusting = false;
  16.    static Class class$com$sun$java$swing$event$ChangeListener;
  17.  
  18.    public DefaultBoundedRangeModel() {
  19.    }
  20.  
  21.    public DefaultBoundedRangeModel(int value, int extent, int min, int max) {
  22.       if (max >= min && value >= min && value + extent <= max) {
  23.          this.value = value;
  24.          this.extent = extent;
  25.          this.min = min;
  26.          this.max = max;
  27.       } else {
  28.          throw new IllegalArgumentException("invalid range properties");
  29.       }
  30.    }
  31.  
  32.    public void addChangeListener(ChangeListener l) {
  33.       EventListenerList var10000 = this.listenerList;
  34.       Class var10001 = class$com$sun$java$swing$event$ChangeListener;
  35.       if (var10001 == null) {
  36.          try {
  37.             var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
  38.          } catch (ClassNotFoundException var2) {
  39.             throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  40.          }
  41.  
  42.          class$com$sun$java$swing$event$ChangeListener = var10001;
  43.       }
  44.  
  45.       var10000.add(var10001, l);
  46.    }
  47.  
  48.    protected void fireStateChanged() {
  49.       Object[] listeners = this.listenerList.getListenerList();
  50.  
  51.       for(int i = listeners.length - 2; i >= 0; i -= 2) {
  52.          Object var10000 = listeners[i];
  53.          Class var10001 = class$com$sun$java$swing$event$ChangeListener;
  54.          if (var10001 == null) {
  55.             try {
  56.                var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
  57.             } catch (ClassNotFoundException var3) {
  58.                throw new NoClassDefFoundError(((Throwable)var3).getMessage());
  59.             }
  60.  
  61.             class$com$sun$java$swing$event$ChangeListener = var10001;
  62.          }
  63.  
  64.          if (var10000 == var10001) {
  65.             if (this.changeEvent == null) {
  66.                this.changeEvent = new ChangeEvent(this);
  67.             }
  68.  
  69.             ((ChangeListener)listeners[i + 1]).stateChanged(this.changeEvent);
  70.          }
  71.       }
  72.  
  73.    }
  74.  
  75.    public int getExtent() {
  76.       return this.extent;
  77.    }
  78.  
  79.    public int getMaximum() {
  80.       return this.max;
  81.    }
  82.  
  83.    public int getMinimum() {
  84.       return this.min;
  85.    }
  86.  
  87.    public int getValue() {
  88.       return this.value;
  89.    }
  90.  
  91.    public boolean getValueIsAdjusting() {
  92.       return this.isAdjusting;
  93.    }
  94.  
  95.    public void removeChangeListener(ChangeListener l) {
  96.       EventListenerList var10000 = this.listenerList;
  97.       Class var10001 = class$com$sun$java$swing$event$ChangeListener;
  98.       if (var10001 == null) {
  99.          try {
  100.             var10001 = Class.forName("com.sun.java.swing.event.ChangeListener");
  101.          } catch (ClassNotFoundException var2) {
  102.             throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  103.          }
  104.  
  105.          class$com$sun$java$swing$event$ChangeListener = var10001;
  106.       }
  107.  
  108.       var10000.remove(var10001, l);
  109.    }
  110.  
  111.    public void setExtent(int n) {
  112.       int newExtent = Math.max(0, n);
  113.       if (this.value + newExtent > this.max) {
  114.          newExtent = this.max - this.value;
  115.       }
  116.  
  117.       this.setRangeProperties(this.value, newExtent, this.min, this.max, this.isAdjusting);
  118.    }
  119.  
  120.    public void setMaximum(int n) {
  121.       int newMin = Math.min(n, this.min);
  122.       int newValue = Math.min(n, this.value);
  123.       int newExtent = Math.min(n - newValue, this.extent);
  124.       this.setRangeProperties(newValue, newExtent, newMin, n, this.isAdjusting);
  125.    }
  126.  
  127.    public void setMinimum(int n) {
  128.       int newMax = Math.max(n, this.max);
  129.       int newValue = Math.max(n, this.value);
  130.       int newExtent = Math.min(newMax - newValue, this.extent);
  131.       this.setRangeProperties(newValue, newExtent, n, newMax, this.isAdjusting);
  132.    }
  133.  
  134.    public void setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) {
  135.       if (newMin > newMax) {
  136.          newMin = newMax;
  137.       }
  138.  
  139.       if (newValue > newMax) {
  140.          newMax = newValue;
  141.       }
  142.  
  143.       if (newValue < newMin) {
  144.          newMin = newValue;
  145.       }
  146.  
  147.       if (newExtent + newValue > newMax) {
  148.          newExtent = newMax - newValue;
  149.       }
  150.  
  151.       if (newExtent < 0) {
  152.          newExtent = 0;
  153.       }
  154.  
  155.       boolean isChange = newValue != this.value || newExtent != this.extent || newMin != this.min || newMax != this.max || adjusting != this.isAdjusting;
  156.       if (isChange) {
  157.          this.value = newValue;
  158.          this.extent = newExtent;
  159.          this.min = newMin;
  160.          this.max = newMax;
  161.          this.isAdjusting = adjusting;
  162.          this.fireStateChanged();
  163.       }
  164.  
  165.    }
  166.  
  167.    public void setValue(int n) {
  168.       int newValue = Math.max(n, this.min);
  169.       if (newValue + this.extent > this.max) {
  170.          newValue = this.max - this.extent;
  171.       }
  172.  
  173.       this.setRangeProperties(newValue, this.extent, this.min, this.max, this.isAdjusting);
  174.    }
  175.  
  176.    public void setValueIsAdjusting(boolean b) {
  177.       this.setRangeProperties(this.value, this.extent, this.min, this.max, b);
  178.    }
  179.  
  180.    public String toString() {
  181.       String modelString = "value=" + this.getValue() + ", " + "extent=" + this.getExtent() + ", " + "min=" + this.getMinimum() + ", " + "max=" + this.getMaximum() + ", " + "adj=" + this.getValueIsAdjusting();
  182.       return this.getClass().getName() + "[" + modelString + "]";
  183.    }
  184. }
  185.